package bdJMSSever;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class TimeIsOn {

	public static void main(String[] args) {
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		   try {
			   Date time1  = dateFormat.parse("2017-3-11");
			   Date time2 = dateFormat.parse("2017-3-15");
			   Date time3 = dateFormat.parse("2017-3-17");
			   Date from = dateFormat.parse("2017-3-12");
			   Date to= dateFormat.parse("2017-3-16");
			   System.out.println(belongCalendar(time1,from,to));
			   System.out.println(belongCalendar(time2,from,to));
			   System.out.println(belongCalendar(time3,from,to)); 
			
		} catch (Exception e) {
			// TODO: handle exception
		}

	}
	
	 public static boolean belongCalendar(Date time, Date from, Date to) {
	        Calendar date = Calendar.getInstance();
	        date.setTime(time);

	        Calendar after = Calendar.getInstance();
	        after.setTime(from);

	        Calendar before = Calendar.getInstance();
	        before.setTime(to);

	        if (date.after(after) && date.before(before)) {
	            return true;
	        } else {
	            return false;
	        }
	    }

}
